$OpenBSD: patch-common_ECLogger_cpp,v 1.23 2016/08/12 08:09:05 robert Exp $
--- common/ECLogger.cpp.orig	Mon Aug  8 09:19:14 2016
+++ common/ECLogger.cpp	Mon Aug  8 09:23:17 2016
@@ -27,6 +27,10 @@
 #include <zarafa/stringutil.h>
 #include "charset/localeutil.h"
 
+#ifdef __OpenBSD__
+#include <signal.h>
+#endif
+
 #ifdef LINUX
 #include "config.h"
 #include <poll.h>
@@ -72,9 +76,11 @@ static ECLogger *ec_log_target = &ec_log_fallback_targ
 ECLogger::ECLogger(int max_ll) {
 	max_loglevel = max_ll;
 	pthread_mutex_init(&m_mutex, NULL);
+#ifndef __OpenBSD__
 	// get system locale for time, NULL is returned if locale was not found.
 	timelocale = createlocale(LC_TIME, "C");
 	datalocale = createUTF8Locale();
+#endif
 	prefix = LP_NONE;
 	m_ulRef = 1;
 }
@@ -83,11 +89,13 @@ ECLogger::~ECLogger() {
 	if (ec_log_target == this)
 		ec_log_set(NULL);
 
+#ifndef __OpenBSD__
 	if (timelocale)
 		freelocale(timelocale);
 
 	if (datalocale)
 		freelocale(datalocale);
+#endif
 	pthread_mutex_destroy(&m_mutex);
 }
 
@@ -107,9 +115,11 @@ std::string ECLogger::MakeTimestamp() {
 
 	char buffer[_LOG_TSSIZE];
 
+#ifndef __OpenBSD__
 	if (timelocale)
 		strftime_l(buffer, sizeof buffer, "%c", &local, timelocale);
 	else
+#endif
 		strftime(buffer, sizeof buffer, "%c", &local);
 
 	return buffer;
@@ -176,7 +186,11 @@ int ECLogger::snprintf(char *str, size_t size, const c
 	int len = 0;
 
 	va_start(va, format);
+#ifndef __OpenBSD__
 	len = _vsnprintf_l(str, size, format, datalocale, va);
+#else
+	len = _vsnprintf_l(str, size, format, va);
+#endif
 	va_end(va);
 
 	return len;
@@ -407,7 +421,11 @@ void ECLogger_File::Log(unsigned int loglevel, const c
 
 void ECLogger_File::LogVA(unsigned int loglevel, const char *format, va_list& va) {
 	char msgbuffer[_LOG_BUFSIZE];
+#ifndef __OpenBSD__
 	_vsnprintf_l(msgbuffer, sizeof msgbuffer, format, datalocale, va);
+#else
+	_vsnprintf_l(msgbuffer, sizeof msgbuffer, format, va);
+#endif
 
 	Log(loglevel, std::string(msgbuffer));
 }
@@ -467,7 +485,11 @@ void ECLogger_Syslog::LogVA(unsigned int loglevel, con
 	vsyslog(levelmap[loglevel & EC_LOGLEVEL_MASK], format, va);
 #else
 	char msgbuffer[_LOG_BUFSIZE];
+#ifndef __OpenBSD__
 	_vsnprintf_l(msgbuffer, sizeof msgbuffer, format, datalocale, va);
+#else
+	_vsnprintf_l(msgbuffer, sizeof msgbuffer, format, va);
+#endif
 	syslog(levelmap[loglevel & EC_LOGLEVEL_MASK], "%s", msgbuffer);
 #endif
 }
@@ -631,7 +653,11 @@ void ECLogger_Tee::LogVA(unsigned int loglevel, const 
 	LoggerList::iterator iLogger;
 
 	char msgbuffer[_LOG_BUFSIZE];
+#ifndef __OpenBSD__
 	_vsnprintf_l(msgbuffer, sizeof msgbuffer, format, datalocale, va);
+#else
+	_vsnprintf_l(msgbuffer, sizeof msgbuffer, format, va);
+#endif
 
 	for (iLogger = m_loggers.begin(); iLogger != m_loggers.end(); ++iLogger)
 		(*iLogger)->Log(loglevel, std::string(msgbuffer));
@@ -682,7 +708,7 @@ void ECLogger_Pipe::Log(unsigned int loglevel, const s
 #ifdef WIN32
 		len = snprintf(msgbuffer + off, sizeof msgbuffer - off, "[%p] ", pthread_self());
 #else
-	len = snprintf(msgbuffer + off, sizeof msgbuffer - off, "[0x%08x] ", (unsigned int)pthread_self());
+	len = snprintf(msgbuffer + off, sizeof msgbuffer - off, "[0x%08x] ", (uintptr_t)pthread_self());
 #endif
 	else if (prefix == LP_PID)
 		len = snprintf(msgbuffer + off, sizeof msgbuffer - off, "[%5d] ", getpid());
@@ -730,7 +756,7 @@ void ECLogger_Pipe::LogVA(unsigned int loglevel, const
 #ifdef WIN32
 		len = snprintf(msgbuffer + off, sizeof msgbuffer - off, "[%p] ", pthread_self());
 #else
-	len = snprintf(msgbuffer + off, sizeof msgbuffer - off, "[0x%08x] ", (unsigned int)pthread_self());
+	len = snprintf(msgbuffer + off, sizeof msgbuffer - off, "[0x%08x] ", (uintptr_t)pthread_self());
 #endif
 	else if (prefix == LP_PID)
 		len = snprintf(msgbuffer + off, sizeof msgbuffer - off, "[%5d] ", getpid());
@@ -741,7 +767,11 @@ void ECLogger_Pipe::LogVA(unsigned int loglevel, const
 		off += len;
 
 	// return value is what WOULD have been written if enough space were available in the buffer
+#ifndef __OpenBSD__
 	len = _vsnprintf_l(msgbuffer + off, sizeof msgbuffer - off - 1, format, datalocale, va);
+#else
+	len = _vsnprintf_l(msgbuffer + off, sizeof msgbuffer - off - 1, format, va);
+#endif
 	// -1 can be returned on formatting error (eg. %ls in C locale)
 	if (len < 0)
 		len = 0;
@@ -824,9 +854,13 @@ namespace PrivatePipe {
 		fd_set readfds;
 #endif
 
+#if defined(__linux__)
 		confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer));
 		if (strncmp(buffer, "linuxthreads", strlen("linuxthreads")) == 0)
 			bNPTL = false;
+#elif defined(__OpenBSD__)
+		bNPTL = true;
+#endif
 
 		m_lpConfig = lpConfig;
 		m_lpFileLogger = lpFileLogger;
@@ -1202,8 +1236,12 @@ void generic_sigsegv_handler(ECLogger *lpLogger, const
 #endif
 	ec_log_crit("Signal errno: %s, signal code: %d", strerror(si->si_errno), si->si_code);
 	ec_log_crit("Sender pid: %d, sender uid: %d, si_status: %d", si->si_pid, si->si_uid, si->si_status);
-	ec_log_crit("User time: %ld, system time: %ld, signal value: %d", si->si_utime, si->si_stime, si->si_value.sival_int);
+	ec_log_crit("User time: %lld, system time: %lld, signal value: %d", si->si_utime, si->si_stime, si->si_value.sival_int);
+#ifndef __OpenBSD__
 	ec_log_crit("Faulting address: %p, affected fd: %d", si->si_addr, si->si_fd);
+#else
+	ec_log_crit("Faulting address: %p", si->si_addr);
+#endif
 	lpLogger->Log(EC_LOGLEVEL_FATAL, "When reporting this traceback, please include Linux distribution name (and version), system architecture and Zarafa version.");
 #ifndef _WIN32
 	/*
